package com.sgb.kjwl.view.ui.adapter.pick.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.TenderInquiryType;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.ArrayList;
import java.util.List;

public class PickDetailInquiryAdapter extends BaseRecycleAdapter<TenderInquiryType> {

    private TextView answerContent;
    private TextView questionContent;

    public PickDetailInquiryAdapter(Context context, List<TenderInquiryType> datas) {
        super(context, R.layout.item_pick_detial_inquiry, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final TenderInquiryType entity) {
        holder.setBinding(BR.viewModel, entity);
        answerContent = holder.getItem().findViewById(R.id.answer_content);
        questionContent = holder.getItem().findViewById(R.id.question_content);
        answerContent.setText("答复内容:  " + entity.getAnswer());
        questionContent.setText("疑问事项:  " + entity.getQuestion());

        List<TenderInquiryType.CustomField> customFieldList = entity.getCustomFieldList();
        List<TenderInquiryType.CustomField> newCustomFieldList = new ArrayList<>();
        if (!TextUtils.isEmpty(entity.getComprehend())) {
            newCustomFieldList.add(0, new TenderInquiryType.CustomField("我的理解:  ", entity.getComprehend()));
        }
        if (!TextUtils.isEmpty(entity.getRequestAnswer())) {
            newCustomFieldList.add(1, new TenderInquiryType.CustomField("请求答复:  ", entity.getRequestAnswer()));
        }

        for (TenderInquiryType.CustomField customField : customFieldList) {
            if (!TextUtils.isEmpty(customField.getValue())) {
                customField.setTitle("自定义:  ");
                newCustomFieldList.add(customField);
            }
        }

        RecyclerView recyclerView = holder.getItem().findViewById(R.id.custom_field_list);
        if (newCustomFieldList.size() > 0) {
            GridLayoutManager rightManager = new GridLayoutManager(context, 1);
            recyclerView.setLayoutManager(rightManager);
            PickDetailInquiryCustomAdapter pickDetailInquiryCustomAdapter = new PickDetailInquiryCustomAdapter(context, newCustomFieldList);
            recyclerView.setAdapter(pickDetailInquiryCustomAdapter);
        } else {
            recyclerView.setVisibility(View.GONE);
        }
    }
}
